package com.kara.webapp.components.clazz;

import java.util.List;

import org.apache.tapestry5.Asset;
import org.apache.tapestry5.annotations.ActivationRequestParameter;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.appfuse.model.User;

import com.kara.entity.Clazz;
import com.kara.entity.SchoolYear;
import com.kara.service.ClazzManager;
import com.kara.webapp.components.student.StudentList;
import com.kara.webapp.pages.admin.clazz.ClazzEdit;
import com.kara.webapp.pages.admin.student.StudentAdmin;

public class ClazzList {

  @ActivationRequestParameter
  private long schoolYearId;

  @Property
  @Persist
  private User user;

  @Inject
  private ClazzManager clazzManager;

  @Property
  private Clazz currentClazz;

  @Property
  private List<Clazz> allClazzes;

  @InjectPage
  private ClazzEdit clazzEdit;

  @InjectPage
  private StudentAdmin studentAdmin;

  @Property
  @Inject
  @Path("context:/images/16x16/Write.gif")
  private Asset editImg;

  @Property
  @Inject
  @Path("context:/images/16x16/Cancel.gif")
  private Asset delteImg;

  void beginRender() {
    if (schoolYearId > 0) {
      allClazzes = clazzManager.getAllClazz(new SchoolYear(schoolYearId));
    }
    else {
      allClazzes = clazzManager.getAllClazzForCurrentSchoolYear();
    }
  }

  Object onActionFromEdit(long id) {
    clazzEdit.setId(id);
    return clazzEdit;
  }

  Object onActionFromDelete(long id) {
    clazzManager.delete(id);
    return null;
  }
  Object onActionFromEditStudent(long clazzId) {
    
    studentAdmin.setMyClazzId(clazzId);
    return StudentAdmin.class;
  }

}
